
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="X-UA-Compatible" content="IE=9" />
        <?php include "jquery.php" ?>
        <link href="style3.css" rel="stylesheet" type="text/css" />
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        
        <title></title>
    </head>
    <body>
        <?php
//include 'functions.php';
// Connect to the database
        session_start();
        $member_id = $_SESSION['member_id'];
        $dbLink = mysql_connect('localhost', 'root', '');
        if (!$dbLink) {
            die("MySQL connection failed");
        }

        mysql_select_db("mydb");

//query to retrieve all messages where the user is a reciever
        $result = mysql_query("SELECT m.first_name, m.last_name, ms.subject, s.message_id FROM member m
         INNER JOIN member_message_member s
         ON (m.member_id = s.member_id1)
         INNER JOIN messages ms ON s.message_id=ms.message_id
            WHERE s.member_id2='$member_id'") or die(mysql_error());

// Check if it was successfull
        if ($result) {

            $num_results = mysql_num_rows($result);
            // Make sure there are some rows in the database
            if ($num_results == 0) {
                echo "<p align='center'>You have no messages.</p>";
            } else {
                echo '<p class="flip">Show/Hide Messages</p>';
                echo "<div class='panel'>";
                // Print the top of a table
                echo '<table id="table">
                <tr>
                    <td><b>From</b></td>
                    <td><b>Subject</b></td>
                </tr>';
                // Print each file
                while ($row = mysql_fetch_assoc($result)) {

                    $update = mysql_query("UPDATE `messages` SET `messages`.`seen` = TRUE WHERE message_id={$row['message_id']}") or die(mysql_error());
                    echo "
                <tr>
                    <td>{$row['first_name']}{$row['last_name']}</td>
                    <td><a href='viewMessage.php?message_id={$row['message_id']}'>{$row['subject']}</a></td>
                    <td><a href='deleteM.php?message_id={$row['message_id']}'>delete</a></td>
                </tr>";
                }
                // Close table
                echo '</table>';
                echo '</div>';
            }
        } else {
            // if connetion to database failed
            echo 'Error! SQL query failed:';
        }
// Close the mysql connection
        mysql_close($dbLink);
        ?>
        
    </body>
</html>
<head>
    <script type='text/javascript' src="sysJavascript.js"></script>
</head>
        <?php
        $con = mysql_connect('localhost', 'root', '');
        mysql_select_db("mydb");

        //query to retrieve all the oncferences where the user is the creator
        $sql = ("SELECT DISTINCT c.conference_id, c.long_name FROM conference c
            INNER JOIN member_privileges m ON (m.conference_id = c.conference_id)
            WHERE (c.creator_id='$member_id') OR (m.member_id = '$member_id') AND (privileges_id = '2')");
        $result = mysql_query($sql) or die(mysql_error());
        $num_rows = mysql_num_rows($result);
        mysql_close($con);

        //creating the drop down list
        if ($num_rows > 0) {
            echo "<form name='chooseconference' action='choosepeople.php' method='POST'>
    Conference: <select name='conference'>";

            for ($i = 0; $i < $num_rows; $i++) {
                $conference_id = mysql_result($result, $i, 0);
                $short_name = mysql_result($result, $i, 1);
                echo '<option value="' . $conference_id . '">' . $short_name . '</option>';
            }

            echo "</select>
    </br>
    <input type='submit' value='Create Message' name='submit' />
</form>";
        } else {
            echo "<p align='center'> You are not organizer of any conference to send message </p>";
        }
        ?>
